<!--
 * @FilePath     : /study_code/layui/10-1.html
 * @Description  : dropdown 基础使用
 * @Date         : 2025-04-09 10:34:32
 * @Author       : Fang YingGui
 * @LastEditors  : fangyinggui 18715384437@163.com
 * @LastEditTime : 2025-04-09 10:38:19
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>documentName</title>
    <link rel="stylesheet" href="/layui/dist/css/layui.css" />
  </head>
  <body>
    <button class="layui-btn" id="demo1">
      下拉菜单
      <i class="layui-icon layui-icon-down layui-font-12"></i>
    </button>

    <script src="/layui/dist/layui.js"></script>
    <script>
      layui.use('dropdown', function () {
        var dropdown = layui.dropdown
        dropdown.render({
          elem: '#demo1', //可绑定在任意元素中，此处以上述按钮为例
          data: [
            {
              title: 'menu item 1',
              id: 100,
              href: '#',
            },
            {
              title: 'menu item 2',
              id: 101,
              href: 'https://www.layui.com/', //开启超链接
              target: '_blank', //新窗口方式打开
            },
            { type: '-' },
            {
              title: 'menu item 3',
              id: 102,
              type: 'group', //菜单类型，支持：normal/group/parent/-
              child: [
                {
                  title: 'menu item 3-1',
                  id: 103,
                },
                {
                  title: 'menu item 3-2',
                  id: 104,
                  child: [
                    {
                      title: 'menu item 3-2-1',
                      id: 105,
                    },
                    {
                      title: 'menu item 3-2-2',
                      id: 106,
                    },
                  ],
                },
                {
                  title: 'menu item 3-3',
                  id: 107,
                },
              ],
            },
            { type: '-' },
            {
              title: 'menu item 4',
              id: 108,
            },
            {
              title: 'menu item 5',
              id: 109,
              child: [
                {
                  title: 'menu item 5-1',
                  id: 11111,
                  child: [
                    {
                      title: 'menu item 5-1-1',
                      id: 2111,
                    },
                    {
                      title: 'menu item 5-1-2',
                      id: 3111,
                    },
                  ],
                },
                {
                  title: 'menu item 5-2',
                  id: 52,
                },
              ],
            },
            { type: '-' },
            {
              title: 'menu item 6',
              id: 6,
              type: 'group',
              isSpreadItem: false,
              child: [
                {
                  title: 'menu item 6-1',
                  id: 61,
                },
                {
                  title: 'menu item 6-2',
                  id: 62,
                },
              ],
            },
          ],
          id: 'demo1',
          //菜单被点击的事件
          click: function (obj) {
            console.log(obj)
            layer.msg('回调返回的参数已显示再控制台')
          },
        })
      })
    </script>
  </body>
</html>
